unit MyConnector;

{$mode objfpc}{$H+}

interface

uses nntpsend, MyFormatter, MyTypes, SysUtils;

type

TConnector = class (TNNTPSend)
private
  formatter: TFormatter;
  server: TNNTPServer;
 { sender: TNNTPSend;}
protected
public
  procedure ConnectToServer( serv: TNNTPServer);
  procedure Disconnect();
  procedure GetGroups(var Groups:TGroupList) ;
  procedure GetMessages(group: TGroup; var messages:TMessageList);
{  constructor Create();}
end;

implementation

{constructor TConnector.Create();
begin
     self.sender:= TNNTPSend.Create ;
     formatter:=  TFormatter.Create ;
end;}

procedure TConnector.ConnectToServer( serv: TNNTPServer);
begin
	 {=== LOGIN ===}
  formatter:=  TFormatter.Create ;  {-}

  self.server:= TNNTPServer.Create() ;
  self.server := serv;

  self.{sender.}TargetHost:=server.Name;
  self.{sender.}TargetPort:=server.Port;

  //LOGIN+PasswordEdit
  If not(server.Username  = '') then
    begin
      self.{sender.}UserName:=server.Username;
      If not(server.Password = '' ) then
        self.{sender.}Password:=server.Password;
    end;

 self.{sender.}Login;

end;

	
procedure TConnector.Disconnect(); 
begin 
  self.{sender.}Logout;
  self.{sender.}Free;
end;

procedure TConnector.GetGroups(var groups:TGroupList) ;
var i:integer;
begin
 self.{sender.}ListGroups;
 formatter.GetGroups(self.{sender.}Data, groups);
end;

procedure TConnector.GetMessages(group: TGroup; var messages:TMessageList);
var i,j: integer; mess:TMessage;
begin
     self.{sender.}SelectGroup(group.Name);
     SetLength(messages,2);
     i:= 0;
     for j:=group.FirstNumber to group.LastNumber do
     begin
          self.{sender.}GetStat(IntToStr(j));
          self.{sender.}GetArticle(IntToStr(j));
	mess:= formatter.GetMessage(group.Id,self.{sender.}ResultString, self.{sender.}Data, ''); {Tmessage}
	i:=i+1;
        SetLength(messages, i);
	messages[i-1]:= mess;
    end; {for}
     
end;

end.

